export default {
    data() {
        return {
            loading: false,
            search: {},
            list: [],
            page: {
                total: 10,
                page: 1,
                rows: 10
            },
            api: null
        }
    },
    methods: {
        async getList() {
            this.loading = true
            let req = {
                ...this.search,
                ...this.page
            }
            delete req.total
            try {
                const {data} = await this.api(req)
                if (data.list === undefined) {
                    this.list = data.rows
                    this.page.total = Number(data.total)
                } else {
                    this.list = data.list
                    this.page.total = Number(data.totalPages) * 10
                }
            } catch (e) {
                console.error(e)
            }
            this.loading = false
        },
        handlerSearch() {
            this.page.page = 1
            this.getList()
        },
        handlerPageChange(num) {
            this.page.page = num
            this.getList()
        }
    }
}
